//
//  AppDelegate.m
//  TravelOcean
//
//  Created by double Mac on 15/3/7.
//  Copyright (c) 2015年 double Mac. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor lightGrayColor];
    
    LeftDrawerViewController *leftVC = [[LeftDrawerViewController alloc] init];
    
    // 首页视图
    HotSpotsViewController *hotVC = [[HotSpotsViewController alloc] init];
    self.hotNaVC = [[UINavigationController alloc] initWithRootViewController:hotVC];
    [self.hotNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav@2x.png"] forBarMetrics:UIBarMetricsDefault];
    self.hotNaVC.navigationBar.translucent = NO;
    
    [_hotNaVC release];

    // 抽屉效果
    self.drawerViewController = [[JVFloatingDrawerViewController alloc] init];
    // 指定左侧视图
    self.drawerViewController.leftViewController = leftVC;
    // 指定中心视图
    self.drawerViewController.centerViewController = self.hotNaVC;
    // 抽屉视图背景图片
    self.drawerViewController.backgroundImage = [UIImage imageNamed:@"sky@3x.jpg"];
    // 切换动画
    self.drawerViewController.animator = [[JVFloatingDrawerSpringAnimator alloc] init];
    // 指定抽屉效果为根视图
    self.window.rootViewController = self.drawerViewController;
    
    [self.window makeKeyAndVisible];
    [_window release];
    
    
    return YES;
}

#pragma mark -- 抽屉视图创建
- (JVFloatingDrawerViewController *)drawerViewController {
    if (!_drawerViewController) {
        _drawerViewController = [[JVFloatingDrawerViewController alloc] init];
    }
    
    return _drawerViewController;
}

#pragma mark -- 热门景点视图创建
- (UIViewController *)hotSpotsViewController {
    
    if (!_hotSpotsViewController) {
        _hotSpotsViewController = [[HotSpotsViewController alloc] init];
        _hotNaVC = [[UINavigationController alloc] initWithRootViewController:_hotSpotsViewController];
        [_hotNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav@2x.png"] forBarMetrics:UIBarMetricsDefault];
        _hotNaVC.navigationBar.translucent = NO;
    }
    
    return self.hotNaVC;
}

#pragma mark -- 精品游记视图创建
- (UIViewController *)rootViewController {

    if (!_rootViewController) {
        _rootViewController = [[RootViewController alloc] init];
        self.rootNaVC = [[UINavigationController alloc] initWithRootViewController:_rootViewController];
        [self.rootNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav@2x.png"] forBarMetrics:UIBarMetricsDefault];
        self.rootNaVC.navigationBar.translucent = NO;
    }
    
    return self.rootNaVC;
}

#pragma mark -- 类方法
+ (AppDelegate *)globalDelegate {
    return (AppDelegate *)[UIApplication sharedApplication].delegate;
}

- (void)toggleLeftDrawer:(id)sender animated:(BOOL)animated {
    [self.drawerViewController toggleDrawerWithSide:JVFloatingDrawerSideLeft animated:animated completion:nil];
}

- (void)toggleRightDrawer:(id)sender animated:(BOOL)animated {
    [self.drawerViewController toggleDrawerWithSide:JVFloatingDrawerSideRight animated:animated completion:nil];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
